CentOS 5
Sponsored Link

Get the date of last update of users's Password
  Get the date of last update of users's Password. If it is about a user, it's simply, the commandd is "chage -l user". But it's trouble to input commands for a user if users are many. So, the example below is the way of display all user's one at one time.

[1] Example
[root@dlp ~]#
cut -d: -f1 /etc/passwd | while read line; do echo -n $line; chage -l $line | head -1 | awk -F: '{print $2}'; done

root Sep 12, 2009
bin Sep 12, 2009
daemon Sep 12, 2009
adm Sep 12, 2009
hiroyuki Sep 30, 2009
postfix Oct 17, 2009
[2] If OS is Solaris or othes that does not have a command 'chage it's impossible to get get them like above, so Change the code like below. All OK.
[root@dlp ~]#
vi lastchange.sh


#!/bin/sh

IFS=:
today=`expr \`date +%s\` / 60 / 60 / 24`
while read a b c d e f g h i; do
    if [ "$b" != '*' -a "$b" != '!!' ]; then
    last=`expr $today - $c`
    echo "$a = `date --date "-$last day" +%Y/%m/%d`"
    fi
done < /etc/shadow


[root@dlp ~]#
chmod 700 lastchange.sh

[root@rx7 ~]#
./lastchange.sh

root = 2009/09/12
cent = 2009/09/14
hiroyuki = 2009/10/20
 
Tweet